package com.aitaoxue.palx;

import java.util.Stack;
import cn.jpush.android.util.ac;

import android.app.Activity;

public class AppManager {

	private static Stack<Activity> activityStack;
	private static AppManager instance;
	
	private AppManager(){
		
	}
	
	public static AppManager getAppManager(){
		if(instance==null){
			instance=new AppManager();
		}
		
		return instance;
	}
	
	public void addActivity(Activity activity){
		if(activityStack==null){
			activityStack=new Stack<Activity>();
		}
		activityStack.add(activity);
	}
	
	public Activity currentActivity(){
		Activity activity=activityStack.lastElement();
		return activity;
	}
	
	public Activity finishActivity(){
		Activity activity=activityStack.lastElement();
		return activity;
	}
	
	public void finishActivity(Activity activity){
		if(activity!=null&&!activity.isFinishing()){
			activityStack.remove(activityStack);
			activity.finish();
			activity=null;
		}
	}
	
	public void finishActivity(Class<?> cls){
		for(Activity activity:activityStack){
			if(activity.getClass().equals(cls)){
				finishActivity(activity);
			}
		}
	}
	
	public void finishAllActivity(){
		for(Activity activity:activityStack){
			if(activity!=null){
				finishActivity(activity);
			}
		}
		activityStack.clear();
	}
	
	
}













